#include "server_listener.h"
#include "gui.h"
#include <QString>


Server::Server(QObject *parent):QTcpServer(parent)
{
	clients_num=0;
	connect(this,SIGNAL(newConnection()),this,SLOT(add_client()));
};



Server::~Server()
{

};



void Server::add_client()
{
	clients[clients_num]=nextPendingConnection();
	
	QString st="Martinka smrdi!!!!!";
	send_string(st,clients[clients_num]);
	
	++clients_num;

};



void Server::send_string(QString s, QTcpSocket* r)
{
	QByteArray block;
	QDataStream out(&block, QIODevice::WriteOnly);
	out.setVersion(QDataStream::Qt_4_5);
	out << (quint16)0;
	out << s;
	out.device()->seek(0);
	out << (quint16)(block.size() - sizeof(quint16));
	r->write(block);
};



sl* sl::get_instance()
{
	static sl inst(0);
	return &inst;
};